<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        body {
            background-color: rgb(241, 242, 243)
        }
        .el-header {
            background-color: white
        }
        #footer_center h3 {
            color: white
        }
        #footer_center p {
            margin: 0
        }
        /*去掉指定某一个el-card的内边距*/
        #right_top_card > div {
            padding: 0;
        }
        .title_p {
            margin: 0;
            height: 40px;
            overflow: hidden;
            /*设置省略号相关样式*/
            display: -webkit-box;
            -webkit-line-clamp: 2; /*设置显示行数*/
            -webkit-box-orient: vertical; /*设置纵向排列*/
        }
    </style>
</head>
<body>
<div id="app">
    <el-container>
        <my-header></my-header>
        <el-main style="width: 1200px;margin: 0 auto">
            <el-row gutter="20">
                <el-col span="18">
                    <el-card>
                        <h2 style="color: orange;text-align: center">
                            {{c.title}}
                        </h2>
                        <p style="font-size: 12px;color: #666;text-align: center">
                            作者:{{c.nickname}} | 发布时间:{{c.createTime}} | 阅读次数:{{c.viewCount}}
                        </p>
                        <el-divider></el-divider>
                        <div v-if="c.type!=2">
                            <el-card style="font-size: 12px">
                                <b style="color: #0aa1ed">摘要:</b>
                                {{c.brief}}
                            </el-card>
                            <p v-html="c.content"></p>
                        </div>
                        <div v-else>
                            <video style="width: 100%" :src="c.videoUrl"
                                   controls type="video/mp4"></video>
                        </div>
                    </el-card>
                    <!--评论相关开始-->
                    <el-card style="margin-top: 20px">
                        <p>发一条友善的评论</p>
                        <el-divider></el-divider>
                        <el-row>
                            <el-col span="22">
                                <el-input v-model="comment.content" placeholder="请输入评论的内容..."></el-input>
                            </el-col>
                            <el-col span="2">
                                <el-button @click="post()">发布</el-button>
                            </el-col>
                        </el-row>
                        <!--评论列表开始-->
                        <el-row style="margin-top: 10px" v-for="item in commentArr">
                            <el-col span="2">
                                <el-avatar :src="item.userImgUrl"></el-avatar>
                            </el-col>
                            <el-col span="22">
                                <span style="color: orange;font-weight: bold">{{item.nickname}}:</span>
                                <p style="margin: 5px 0">{{item.content}}</p>
                                <span style="font-size: 12px;color: #666">{{item.createTime}}</span>
                            </el-col>
                        </el-row>
                        <!--评论列表结束-->

                    </el-card>
                    <!--评论相关结束-->

                </el-col>
                <el-col span="6">
                    <el-card id="right_top_card">
                        <div style="background-image: url('imgs/avarbg.jpg');height: 90px"></div>
                        <div style="text-align: center;position: relative;top: -50px">
                            <img :src="c.userImgUrl" style="border: 5px solid white;
                            width: 90px;height: 90px;border-radius: 90px;">
                            <p style="font-weight: bold;margin: 0;font-size: 20px">{{c.nickname}}</p>
                            <i class="el-icon-edit">本文作者</i><br>
                            <i class="el-icon-time">{{c.createTime}}</i>
                        </div>
                    </el-card>
                    <el-card style="margin: 10px 0">
                        <h3>作者其它文章</h3>
                        <el-divider></el-divider>
                        <el-row v-for="item in otherArr" gutter="20">
                            <el-col span="10">
                                <img :src="item.imgUrl" width="100%" height="70">
                            </el-col>
                            <el-col span="14">
                                <p class="title_p">{{item.title}}</p>
                                <i class="el-icon-time">{{item.createTime}}</i>
                            </el-col>
                        </el-row>
                    </el-card>
                    <el-card style="margin: 10px 0">
                        <h3>热门文章</h3>
                        <el-divider></el-divider>
                        <el-row v-for="item in hotArr" gutter="20">
                            <el-col span="10">
                                <img :src="item.imgUrl" width="100%" height="70">
                            </el-col>
                            <el-col span="14">
                                <p class="title_p">{{item.title}}</p>
                                <i class="el-icon-time">{{item.createTime}}</i>
                            </el-col>
                        </el-row>
                    </el-card>
                </el-col>
            </el-row>


        </el-main>
        <el-footer style="background-color: #2f3234;height: 280px;padding: 50px 0">
            <div style="width: 1200px;margin: 0 auto;text-align: center;color: #666">
                <el-row gutter="20">
                    <el-col span="8">
                        <img src="imgs/icon.png">
                        <p>教程灵感就看烘焙坊</p>
                        <p>烘焙行业网络社区平台</p>
                        <p>全国百城上千个职位等你来</p>
                    </el-col>
                    <el-col id="footer_center" span="8">
                        <el-row gutter="20">
                            <el-col span="8">
                                <h3>关于我们</h3>
                                <p>烘焙学院</p>
                                <p>烘焙食谱</p>
                                <p>分类信息</p>
                                <p>求职招聘</p>
                                <p>社区交流</p>
                            </el-col>
                            <el-col span="8">
                                <h3>服务与支持</h3>
                                <p>练习我们</p>
                                <p>广告投放</p>
                                <p>用户协议</p>
                                <p>友情链接</p>
                                <p>在线反馈</p>
                                <p>我发投稿</p>
                            </el-col>
                            <el-col span="8">
                                <h3>底部导航</h3>
                                <p>Archiver</p>
                                <p>手机版</p>
                                <p>小黑屋</p>
                            </el-col>
                        </el-row>
                    </el-col>
                    <el-col span="8">
                        <p style="font-size: 60px;margin: 0">
                            <span style="color: orange">烘焙</span>坊
                        </p>
                        <p>烘焙行业网络社区平台</p>
                    </el-col>
                </el-row>
            </div>
        </el-footer>
    </el-container>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<!--引入Axios框架-->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script src="js/header.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                c: {},
                otherArr: [],
                hotArr: [],
                comment: {content:""},
                commentArr:[]
            }
        },
        methods: {
            loadComments(){
                let id = new URLSearchParams(location.search).get("id");
                //请求所有评论
                axios.get("/v1/comments/"+id).then(function (response) {
                    if (response.data.code==1){
                        v.commentArr = response.data.data;
                    }
                })
            },
            post() {
                if (v.comment.content.trim() == "") {
                    v.$message.error("请输入评论的内容!");
                    return;
                }
                //得到用户信息
                let user = localStorage.user ? JSON.parse(localStorage.user) : null;
                if (user == null) {
                    alert("请先登录!");
                    location.href = "/login.html";
                    return;
                }
                v.comment.userId = user.id;//设置作者id
                v.comment.contentId = v.c.id;//设置文章id
                //发请求
                axios.post("/v1/comments/add-new", v.comment).then(function (response) {
                    if (response.data.code == 1) {
                        v.$message.success("评论完成!");
                        v.comment.content="";
                        v.loadComments();
                    }
                })
            }
        },
        created: function () {
            let id = new URLSearchParams(location.search).get("id");

            this.loadComments();//请求所有评论
            axios.post("/v1/contents/"+id).then(function (response) {
                if (response.data.code == 1) {
                    v.c = response.data.data;
                }
                })

            axios.get("/v1/contents/" + id + "/detail").then(function (response) {
                if (response.data.code == 1) {
                    v.c = response.data.data;
                    //请求其它内容
                    //请求当前文章作者其它内容
                    axios.get("/v1/contents/" + v.c.userId + "/other").then(function (response) {
                        if (response.data.code == 1) {
                            v.otherArr = response.data.data;
                        }
                    })
                }
            })


            //发送请求获取热门文章
            axios.get("/v1/contents/hot").then(function (response) {
                if (response.data.code == 1) {
                    v.hotArr = response.data.data;
                }

            })
        }
    })
</script>
</html>